import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store/index'

import Index from '../components/Index'
//登陆
import Login from '../components/Login'
//项目
import ProjectInfoView from '../components/project/template/ProjectInfoView'
import FileContentView from '../components/project/template/FileContentView'
import demo from '../components/project/template/demo'
import ProjectFolderView from '../components/project/template/ProjectFolderView'
//新建
import CreateFile from '../components/project/template/CreateFile'
//我的
import SetView from '../components/person/template/SetView'
import UpdatePassword from '../components/person/template/UpdatePassword'
import MyRecycleView from '../components/person/template/MyRecycleView'
import AboutUs from '../components/person/template/AboutUs'

//搜索
import SearchView from '../components/common/SearchView'

Vue.use(Router);

const routes = [
    {
        // 首页
        path: '/',
        name: 'index',
        component: Index,
        meta: {
            auth: true
        },
    },
    {
        path: '/login',
        name: 'login',
        component: Login
    },
    // 项目文件列表
    {
        path: '/project/folder',
        name: 'projectFolder',
        component: ProjectFolderView
    },
    // 文档列表
    {
        path: '/project/projectInfo',
        name: 'projectInfo',
        component: ProjectInfoView
    },
    // 文档内容
    {
        path: '/project/fileContent',
        name: 'fileContent',
        component: FileContentView
    },
    {
        path: '/demo',
        name: 'demo',
        component: demo
    },
    {
        path: '/create/createFile',
        name: 'createFile',
        component: CreateFile
    },
    //个人中心--设置
    {
        path: '/person/setInfo',
        name: 'setInfo',
        component: SetView
    },
    //修改密码
    {
        path: '/person/updatePwd',
        name: 'updatePwd',
        component: UpdatePassword
    },
    //回收站
    {
        path: '/person/recycle',
        name: 'recycle',
        component: MyRecycleView
    },
    //关于
    {
        path: '/person/about',
        name: 'about',
        component: AboutUs
    },
    //搜索
    {
        path: '/search',
        name: 'search',
        component: SearchView
    }

];
var router = new Router({
    routes
});
/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return routerPush.call(this, location).catch(error => error)
};
// console.log(store.state.index)

// router.beforeEach((to, form, next) => {
//     if (to.meta.auth) {
//         if (store.state.index.isLogin) {
//             next();
//         } else {
//             next('login');
//         }
//     } else {
//         next();
//     }
// });
export default router;